#ifndef _GUAFS_H_
#define _GUAFS_H_

#define FUSE_USE_VERSION 26
#include "stdio.h"
#include "stdlib.h"
#include <unistd.h>
#include "fcntl.h"
#include "string.h"
#include "fuse.h"
#include <stddef.h>
#include "ddriver.h"
#include "errno.h"
#include "types.h"

#define GUAFS_MAGIC           0x12345678
#define GUAFS_DEFAULT_PERM    0777   /* 全权限打开 */
#define MAX_NAME_LEN    128     
#define BLOCK_SIZE             1024
#define IO_SIZE                512
#define INODE_BLOCK_NUM        1
#define DATA_BLOCK_NUM         6

#define UINT32_BITS             32
#define UINT8_BITS              8
struct custom_options guafs_options;			 /* 全局选项 */
struct guafs_super super; 

/******************************************************************************
* SECTION: guafs_utils.c
*******************************************************************************/

int guafs_driver_read(int offset, uint8_t *out_content, int size);
int guafs_driver_write(int offset, uint8_t *in_content, int size);
struct guafs_inode* guafs_alloc_inode(struct guafs_dentry * dentry);
int guafs_alloc_dataPointers(struct guafs_inode* inode);
int findFreeDataBlock();
int guafs_sync_inode(struct guafs_inode * inode);
struct guafs_inode* guafs_read_inode(struct guafs_dentry * dentry, int ino);
int guafs_alloc_dentry(struct guafs_inode* inode, struct guafs_dentry* dentry);
void guafs_dump_map();
struct guafs_dentry* guafs_lookup(const char * path, int* is_find, int* is_root);
char* guafs_get_fname(const char* path);
int guafs_calc_lvl(const char * path);
struct guafs_dentry* guafs_get_dentry(struct guafs_inode * inode, int dir);
/******************************************************************************
* SECTION: guafs.c
*******************************************************************************/
void* 			   guafs_init(struct fuse_conn_info *);
void  			   guafs_destroy(void *);
int   			   guafs_mkdir(const char *, mode_t);
int   			   guafs_getattr(const char *, struct stat *);
int   			   guafs_readdir(const char *, void *, fuse_fill_dir_t, off_t,
						                struct fuse_file_info *);
int   			   guafs_mknod(const char *, mode_t, dev_t);
int   			   guafs_write(const char *, const char *, size_t, off_t,
					                  struct fuse_file_info *);
int   			   guafs_read(const char *, char *, size_t, off_t,
					                 struct fuse_file_info *);
int   			   guafs_access(const char *, int);
int   			   guafs_unlink(const char *);
int   			   guafs_rmdir(const char *);
int   			   guafs_rename(const char *, const char *);
int   			   guafs_utimens(const char *, const struct timespec tv[2]);
int   			   guafs_truncate(const char *, off_t);
			
int   			   guafs_open(const char *, struct fuse_file_info *);
int   			   guafs_opendir(const char *, struct fuse_file_info *);

#endif  /* _guafs_H_ */